<template>
  <div>
    <cityHeader></cityHeader>
    <citySearch :cities="cities"></citySearch>
    <cityList :hotCities="hotCities" :cities="cities" :letter="letter"></cityList>
    <cityAlphabet :cities="cities" @change="handleClickLetter"></cityAlphabet>
  </div>
</template>

<script>
import axios from 'axios'
import cityHeader from './components/header'
import citySearch from './components/search'
import cityList from './components/list'
import cityAlphabet from './components/alphabet'
export default {
  name: 'city',
  components: {
    cityHeader,
    citySearch,
    cityList,
    cityAlphabet
  },
  data () {
    return {
      hotCities: [],
      cities: {},
      letter: ''
    }
  },
  mounted () {
    this.getCityInfo()
  },
  methods: {
    getCityInfo () {
      axios.get('/static/json/city.json')
        .then(this.getCityInfoSuccess)
    },
    getCityInfoSuccess (result) {
      if (result.status !== 200) alert('获取城市列表数据失败')
      const data = result.data.data
      this.hotCities = data.hotCities
      this.cities = data.cities
    },
    handleClickLetter (letter) {
      this.letter = letter
    }
  }
}
</script>

<style lang="stylus" scoped>
</style>
